﻿<!--{template header,admin}-->
<script src="js/jquery.js" type="text/javascript"></script>
<script src="js/dialog.js" type="text/javascript"></script>
<script src="js/admin.js" type="text/javascript"></script>
<script src="js/calendar.js" type="text/javascript"></script>
<div style="width:100%; height:15px;color:#000;margin:0px 0px 10px;">
    <div style="float:left;"><a href="index.php?admin_main/stat{$setting['seo_suffix']}" target="main"><b>控制面板首页</b></a>&nbsp;&raquo;&nbsp;用户管理</div>
</div>
<div id="append"></div>
<!--{if isset($message)}-->
<!--{eval $type=isset($type)?$type:'correctmsg'; }-->
<table cellspacing="1" cellpadding="4" width="100%" align="center" class="tableborder">
    <tr>
        <td class="{$type}">{$message}</td>
    </tr>
</table>
<!--{/if}-->
<form action="index.php?admin_user/search{$setting['seo_suffix']}" method="post">
    <table width="100%" cellspacing="1" cellpadding="4" align="center" class="tableborder">
        <tbody>
            <tr class="header" ><td colspan="7">用户列表</td></tr>
            <tr class="altbg1"><td colspan="7">可以通过如下搜索条件，检索用户</td></tr>
            <tr>
                <td width="35%" >用户名: <input class="txt" name="srchname"> UID:<input class="txt" name="srchuid"></td>
                <td  width="20%">Email:<input class="txt" name="srchemail"></td>
                <td  width="20%">注册IP:<input class="txt" name="srchregip"></td>
                <td  width="20%"></td>                
            </tr>
            <tr>
                <td  width="30%">注册日期:<input class="txt" onclick="showcalendar();" name="srchregdatestart"> 到 <input class="txt" onclick="showcalendar();" name="srchregdateend"></td>
                <td  width="20%">用户组：
                    <select name="srchgroupid">
                        <option value="0">--不限--</option>
                        <!--{loop $usergrouplist $group}-->
                        <option value="{$group['groupid']}">{$group['grouptitle']}</option>
                        <!--{/loop}-->
                    </select>
                </td>
		<td>分类ID:<input type="text" name="goodatcategory" id="categorys" size="18" onfocus="showselect()"/></td>
                <td rowspan="2" colspan="2"><input class="btn" type="submit" value="提 交"></td>
            </tr>
        </tbody>
    </table>
</form>
<form name="userForm" action="index.php?admin_user/remove{$setting['seo_suffix']}" method="post">
    <table width="100%" border="0" cellpadding="4" cellspacing="1" class="tableborder">
        <tr class="header">
            <td width="6%"><input class="checkbox" id="chkall" onclick="checkall('uid[]')" type="checkbox" name="chkall"><label for="chkall">全选</label></td>
            <td  width="10%">用户名</td>
            <td  width="12%">分类</td>
            <td  width="10%">Email</td>
	    <td  width="12%">手机</td>
            <td  width="10%">注册时间</td>
            <td  width="15%">注册IP</td>            
            <td  width="10%">上次登录时间</td>
            <td  width="10%">已推荐</td>
            <td  width="10%">编辑</td>
        </tr>

        <!--{loop $userlist $member}-->
        <tr>
            <td class="altbg2"><input class="checkbox" type="checkbox" value="{$member['uid']}" name="uid[]"></td>
            <td class="altbg2"><strong>{$member['username']}</strong></td>
            <td class="altbg2"><strong>{$member['name']}</strong></td>
            <td class="altbg2">{$member['email']}</td>
            <td class="altbg2">{$member['phone']}</td>
            <td class="altbg2">{$member['regtime']}</td>
            <td class="altbg2">{$member['regip']}</td>
            <td class="altbg2">{$member['lastlogintime']}</td>
            <td class="altbg2">{if $member['elect']}<font color="Red">是</font>{else}否{/if}</td>
            <td class="altbg2"><a href="index.php?admin_user/edit/$member['uid']{$setting['seo_suffix']}">编辑</a></td>
        </tr>
        <!--{/loop}-->
        <!--{if $departstr}-->
        <tr><td colspan="9" class="altbg2" align="right">{$departstr}</td></tr>
        <!--{/if}-->
        <tr><td colspan="10" class="altbg1" align="left"><input class="button" type="button" name="elect" onclick="commenduser(1);" value="推荐为本周之星" />&nbsp;&nbsp;<input class="button" type="button" name="elect" onclick="commenduser(0);" value="取消推荐" />&nbsp;&nbsp;<input class="button" type="button" name="delete" onclick="remove();" value="删除" /></td></tr>
    </table>
</form>
<br>
<!--{template footer,admin}-->
<script type="text/javascript">

        var sortobj=eval('($category_js)');
    var g_ClassLevel1;
    var g_ClassLevel2;
    var g_ClassLevel3;
    var class_level_1=sortobj.category1;
    var class_level_2=sortobj.category2;
    var class_level_3=sortobj.category3;
    var button_noselect="不选择";

    function getCidValue()
    {
        var _cl1 = document.askform.ClassLevel1;
        var _cl2 = document.askform.ClassLevel2;
        var _cl3 = document.askform.ClassLevel3;
        var _cid = document.askform.cid;
        if(_cl1.value!=0) _cid.value = _cl1.value;
        if(_cl2.value!=0) _cid.value = _cl2.value;
        if(_cl3.value!=0) _cid.value = _cl3.value;
    }
    function FillClassLevel1(ClassLevel1)
    {
        ClassLevel1.options[0] = new Option("aa", "0");
        for(i=0; i<class_level_1.length; i++)
        {
            ClassLevel1.options[i] = new Option(class_level_1[i][1], class_level_1[i][0]);
        }
        // ClassLevel1.options[0].selected = true;
        ClassLevel1.length = i;
    }
    function FillClassLevel2(ClassLevel2, class_level_1_id)
    {
        ClassLevel2.options[0] = new Option(button_noselect, "");
        count = 1;
        for(i=0; i<class_level_2.length; i++){
            if(class_level_2[i][0].toString() == class_level_1_id) {
                ClassLevel2.options[count] = new Option(class_level_2[i][2], class_level_2[i][1]);
                count = count+1;}
        }
        ClassLevel2.options[0].selected = true;
        ClassLevel2.length = count;
    }
    function FillClassLevel3(ClassLevel3, class_level_2_id)
    {
        ClassLevel3.options[0] = new Option(button_noselect, "");
        count = 1;
        for(i=0; i<class_level_3.length; i++) {
            if(class_level_3[i][0].toString() == class_level_2_id) {
                ClassLevel3.options[count] = new Option(class_level_3[i][2], class_level_3[i][1]);
                count = count+1;}
        }
        ClassLevel3.options[0].selected = true;
        ClassLevel3.length = count;
    }
    function ClassLevel2_onchange()
    {
        getCidValue();
        FillClassLevel3(g_ClassLevel3, g_ClassLevel2.value);
        if (g_ClassLevel3.length <= 1) {
            g_ClassLevel3.style.display = "none";
            document.getElementById("jiantou").style.display = "none";
        }
        else {
            g_ClassLevel3.style.display = "";
            document.getElementById("jiantou").style.display = "";
        }
    }
 
    function ClassLevel1_onchange()
    {
        getCidValue();
        FillClassLevel2(g_ClassLevel2, g_ClassLevel1.value);
        ClassLevel2_onchange();
	
    }
    function InitClassLevelList(ClassLevel1, ClassLevel2, ClassLevel3)
    {
        g_ClassLevel1=ClassLevel1;
        g_ClassLevel2=ClassLevel2;
        g_ClassLevel3=ClassLevel3;
        g_ClassLevel1.onchange = Function("ClassLevel1_onchange();");
        g_ClassLevel2.onchange = Function("ClassLevel2_onchange();");
        FillClassLevel1(g_ClassLevel1);
        ClassLevel1_onchange();
    }

    function checkform(form){
        var username = form.username.value;
        var goodatcate = form.goodatcategory.value;
        if(username == '' || goodatcate == '' ){
            alert("用户名或分类不能为空");
            return false;
        }
        return true;
    }

    function showselect(){
 
        var select = $("#selectcategory").html();
        $.dialog({
            id:'addreason',
            position:'center',
            align:'left',
            width:600,
            height:200,
            title:'选择专家擅长分类',
            fnOk:function(){ 
                var cids='';
                $("input[name='cid']").each(function(){
                    cids +=$(this).val()+' ';
                });
                $("#categorys").val(cids);
                $("#ulid").html($("#selectedcate").html());
                $.dialog.close('addreason');            
            },
            fnCancel:function(){$.dialog.close('addreason')},
            content:'已选中的分类：<br /><ul id="selectedcate"></ul><form name="askform" method="POST" action="index.php?adimin_expert/add">'+'<table border="0" cellpadding="0" cellspacing="0" width="100%">'+
                '<tr valign="top">'+
                '<td width="15%">'+
                '<select  id="ClassLevel1" class="catselect2" size="8" name="classlevel1" style="width:100%" >'+
                '<option selected></option>'+
                '</select>'+
                '</td>'+
                '<td align="center" valign="middle" width="3%">'+
                '<div><b>→</b></div>'+
                '</td>'+
                '<td width="15%">'+
                '<select  id="ClassLevel2"  class="catselect2" size="8" name="classlevel2" style="width:100%">'+
                '<option selected></option>'+
                '</select>'+
                '<td align="center" valign="middle" width="3%">'+
                '<div style="display: none;" id="jiantou"><b>→</b></div>'+
                '</td>'+
                '<td width="15%">'+
                '<select id="ClassLevel3"  class="catselect2" size="8" onchange="getCidValue();"  name="classlevel3" style="width:100%">'+
                '<option selected></option>'+
                '</select>'+
                '</td>'+                
                '</tr>'+
                '<tr valign="top">'+
                '<td class="tiw_biaozhu" colspan="6" align="left" valign="middle">所选分类不能重叠，不能相互包含！</td></tr>'+
                '</table>'+
                '<input type="hidden" value="0" name="cid" />'+
                '<input type="hidden" value="0" name="allcid" />'+
                '</form>'
        });
        InitClassLevelList(document.askform.ClassLevel1, document.askform.ClassLevel2, document.askform.ClassLevel3);
        var selected_id_list="0"
        var blank_pos = selected_id_list.indexOf(" ");
        var find_blank = true;
        if (blank_pos == -1) {
            find_blank = false;
            blank_pos = selected_id_list.length;
        }
        $("#selectedcate").html($("#ulid").html());
    }

    function addcategory(){
        var curcid = $("input[name='cid']").val();
        if(curcid == 0){
            alert("您还未选择分类！");
            return false;
        }
        $.ajax({
            type: "POST",
            url: "index.php?admin_expert/ajaxgetname.html",
            data: "cid="+curcid,
            success: function(categorystr){
                if($("#selectedcate li").size()<=2)
                    $("#selectedcate").append('<li style="color:#3F92F8;"><input type="hidden" name="cids[]"  value="'+curcid+'" />'+categorystr+'&nbsp;&nbsp;<a href="#" onclick="delcategory(this);">删除</a></li>');

            }
        });    
    }
    function delcategory(a){
        $(a).parent().remove();
        $("input[name='cid']").val("0");
    }

    function commenduser(type){
        if($("input[name='uid[]']:checked").length > 1){
            alert('只能选择一个用户进行操作');
            return false;
        }
        var uid = $("input[name='uid[]']:checked").val();
        $.dialog({
            id:'addreason',
            position:'center',
            align:'left',
            width:300,
            height:100,
            title:'添加推荐理由',
            fnOk:function(){
                if('' == $.trim($("#reaasondesc").val()) ){
                    alert("入选原因不能为空！");
                    return false;
                }
                document.addreasonForm.submit();
                $.dialog.close('addreason');
            },
            fnCancel:function(){$.dialog.close('addreason')},
            content:'<div class="mainbox">请添加该用户的入选理由（<font color="red">必填项</font>）：<form name="addreasonForm" action="index.php?admin_user/famous/'+type+'{$setting['seo_suffix']}"  method="post" ><input type="hidden" name="uid" id="uidval" value="'+uid+'" /><textarea name="reason" id="reaasondesc" style="width: 100%; padding-top: 1px; font-size: 14px;" rows="4" ></textarea></form></div>'
        });
    }

    function remove(){
        if($("input[name='uid[]']:checked").length == 0){
            alert('你没有选择任何用户');
            return false;
        }
        if(confirm('是否同时删除用户的所有问答？')==true){
            document.userForm.action="index.php?admin_user/remove/all{$setting['seo_suffix']}";
            document.userForm.submit();
        }else{
            document.userForm.action="index.php?admin_user/remove{$setting['seo_suffix']}";
            document.userForm.submit();
        }
    }
</script>


